package com.boodaba.todocarts.test.app;

import org.jmock.Expectations;
import org.junit.runner.RunWith;

import com.boodaba.todocarts.app.IStartupActivity;
import com.boodaba.todocarts.app.StartupPresenter;
import com.googlecode.instinct.integrate.junit4.InstinctRunner;
import com.googlecode.instinct.marker.annotate.BeforeSpecification;
import com.googlecode.instinct.marker.annotate.Mock;
import com.googlecode.instinct.marker.annotate.Specification;
import com.googlecode.instinct.marker.annotate.Subject;

import static com.googlecode.instinct.expect.Expect.expect;

@RunWith(InstinctRunner.class)
public class StartupPresenterSpecs {
	@Subject private StartupPresenter SUT;
	
	@Mock private IStartupActivity startupActivity;
		
	@BeforeSpecification
	public void setUp() {
		SUT = new StartupPresenter();
		SUT.initializeWith(startupActivity);
	}
	
	@Specification
	public void shouldAskVersionsInfoOnUpdating() {
		expect.that(new Expectations() {{
			oneOf(startupActivity).getCurrentVersion();
			oneOf(startupActivity).getDeclaredVersion();
			ignoring(startupActivity);
		}});
		SUT.checkAndUpdate();
	}
	
	@Specification
	public void shouldSetNewCurrentVersion() {
		expect.that(new Expectations() {{
			oneOf(startupActivity).getCurrentVersion(); will(returnValue(1));
			oneOf(startupActivity).getDeclaredVersion(); will(returnValue(2));
			oneOf(startupActivity).setCurrentVersion(2);
			ignoring(startupActivity);
		}});
		SUT.checkAndUpdate();
	}
}
